package pl.druminski.robinhood.controller;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;
import pl.druminski.robinhood.model.Data;
import pl.druminski.robinhood.view.Gui;

/**
 * @author Łukasz Drumiński
 * 
 */
public class ALSave implements ActionListener
{
    private Data data;
    private Gui gui;

    public ALSave(Data data, Gui gui)
    {
        this.data = data;
        this.gui = gui;
    }

    public void actionPerformed(ActionEvent e)
    {
        String tmp = gui.fldStartTime.getText();
        int k;

        if (!tmp.equals(""))
        {
            k = Integer.parseInt(tmp);
            if (k<0) k =0;
            data.setStartTime(k);
        }

        if (gui.chckExit.isSelected())
        {
            tmp = gui.fldExitTime.getText();
            if (!tmp.equals(""))
            {
                k = Integer.parseInt(tmp);
                if (k<0) k =0;
                data.setExitTime(k);
            }
        }

        data.saveConfig();
        JOptionPane.showMessageDialog(null, "Zmiany zostały zapisane");

    }

}
